home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / misc.zoo / misc / getscreen.c next >
Encoding:
C/C++ Source or Header  |  1989-01-24  |  2.5 KB  |  99 lines

  1. /*                        Copyright (c) 1988 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    get_screen        (S A Uhler)
  9.  *
  10.  *    Capture an image of the SUN screen
  11.  */
  12. /*    $Header: getscreen.c,v 1.2 88/07/08 08:25:28 sau Exp $
  13.     $Source: /tmp/mgrsrc/misc/RCS/getscreen.c,v $
  14. */
  15. static char    RCSid_[] = "$Source: /tmp/mgrsrc/misc/RCS/getscreen.c,v $$Revision: 1.2 $";
  16.  
  17. #include <sys/ioctl.h>
  18. #include <sun/fbio.h>
  19. #include <sys/file.h>
  20. #include <sys/mman.h>
  21. #include <stdio.h>
  22. #include "dump.h"
  23.  
  24. #define SCREEN    "/dev/bwtwo0"    /* name of sun frame buffer */
  25. #define BUFF    512        /* size of write buffer */
  26. #define BAR      3        /* width of copy bar */
  27.  
  28. main()
  29.    {
  30.    int fd;
  31.    char  *malloc();
  32.    register unsigned char *addr;
  33.    struct fbtype buff;
  34.    int temp,pagesize;
  35.    register int i, wide;
  36.    struct b_header b_buff, *head = &b_buff;    /* for bitmap header */
  37.  
  38.    /* open the SUN screen */
  39.  
  40.    if ((fd = open(SCREEN,O_RDWR)) <0) {
  41.       fprintf(stderr,"Can' open %s\n",SCREEN);
  42.       exit(1);
  43.       }
  44.  
  45.    /* get the frame buffer size */
  46.  
  47.    ioctl(fd,FBIOGTYPE,&buff);
  48.    pagesize = getpagesize();
  49.    buff.fb_size = (buff.fb_size+pagesize-1) &~ (pagesize-1);
  50.  
  51.    /* malloc space for frame buffer */
  52.  
  53.    if ((temp = (int) malloc(buff.fb_size+pagesize)) == 0) {
  54.       fprintf(stderr,"couldn't malloc %d bytes\n",buff.fb_size+pagesize);
  55.       exit(1);
  56.       }
  57.  
  58.    /* align space on a page boundary */
  59.  
  60.    addr = (unsigned char *)((temp+pagesize-1) & ~(pagesize-1));
  61.  
  62.    /* map the frame buffer into malloc'd space */
  63.  
  64. #ifdef _MAP_NEW
  65.    addr = mmap(addr,buff.fb_size,PROT_WRITE|PROT_READ,_MAP_NEW|MAP_SHARED,fd,0);
  66. #else
  67.    mmap(addr,buff.fb_size,PROT_WRITE|PROT_READ,MAP_SHARED,fd,0);
  68. #endif
  69.   
  70.    /* write header to stdout */
  71.  
  72.    B_PUTOLDHDR(head,buff.fb_width,buff.fb_height);
  73.    write(1,head,B_HSIZE);
  74.    
  75.    /* write the screen to stdout */
  76.  
  77.    wide = buff.fb_width/8;
  78.    for(i=0;i<buff.fb_height;i++) {
  79.       if (i>BAR) invert(addr-BAR*wide,wide);
  80.       write(1,addr,wide);
  81.       invert(addr,wide);
  82.       addr += wide;
  83.       }
  84.    invert(addr-BAR*wide,BAR*wide);
  85.  
  86.    /* clean up stuff */
  87.  
  88.    munmap(addr,buff.fb_size);
  89.    free(temp);
  90.    }
  91.    
  92. invert(addr,count)
  93. register char *addr;
  94. int count;
  95.    {
  96.    register char *max = addr + count;
  97.    while(addr<max) *addr++ = ~*addr;
  98.    }
  99.